# plugs/irc.py
#
#

""" irc related commands """

__copyright__ = 'this file is in the public domain'

from ommbot.world import add_cmnd, add_example

def handle_join(bot, ievent):
    try:
        chan = ievent.args[0]
    except IndexError:
        ievent.missing('<channel> [<password>]')
        return
    try:
        pwd = ievent.args[1]
    except IndexError:
        pwd = None    
    bot.join(chan, pwd)

add_cmnd('join', handle_join, 'OPER')
add_example('join', 'join <channel> [<password>] .. join a channel', '1) \
             join #dunkbots 2) join #dunkbots mekker')

def handle_part(bot, ievent):
    try:
        chan = ievent.args[0]
    except IndexError:
        chan = ievent.channel
    bot.part(chan)

add_cmnd('part', handle_part, 'OPER')
add_example('part', 'part [<channel>] .. part a channel', '1) part 2) part \
             #dunkbots')

def handle_channels(bot, ievent):
    ievent.reply(str(bot.state['channels']))

add_cmnd('channels', handle_channels, ['USER', 'WEB'])
add_example('channels', 'show joined channels', 'channels')
